<template>
  <div class="dashboard">
    <div class="header">
      <h2>实验室能耗监控</h2>
      <el-date-picker
        v-model="date"
        type="date"
        placeholder="选择日期"
        size="small"
      />
    </div>

    <div class="energy-overview">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>总能耗</span>
                <el-tag size="small" type="success">正常</el-tag>
              </div>
            </template>
            <div class="card-content">
              <h3>2,345 kWh</h3>
              <p>较昨日 -5.2%</p>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>实时功率</span>
                <el-tag size="small" type="warning">注意</el-tag>
              </div>
            </template>
            <div class="card-content">
              <h3>12.5 kW</h3>
              <p>较昨日 +2.1%</p>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>设备在线</span>
                <el-tag size="small" type="success">正常</el-tag>
              </div>
            </template>
            <div class="card-content">
              <h3>24/25</h3>
              <p>1台设备离线</p>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="charts-section">
      <el-row :gutter="20" style="margin-bottom: 20px;">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>能耗趋势</span>
                <el-radio-group v-model="timeRange" size="small">
                  <el-radio-button label="day">日</el-radio-button>
                  <el-radio-button label="week">周</el-radio-button>
                  <el-radio-button label="month">月</el-radio-button>
                </el-radio-group>
              </div>
            </template>
            <div class="chart-container">
              <energy-trend-chart height="300px" />
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="20" style="margin-bottom: 20px;">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>送风趋势</span>
              </div>
            </template>
            <div class="chart-container">
              <energy-trend-chart height="300px" />
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <span>排风趋势</span>
              </div>
            </template>
            <div class="chart-container">
              <energy-trend-chart height="300px" />
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="device-list">
      <el-card shadow="hover">
        <template #header>
          <div class="card-header">
            <span>设备状态</span>
            <el-button type="primary" size="small">查看全部</el-button>
          </div>
        </template>
        <el-table :data="deviceList" style="width: 100%">
          <el-table-column prop="name" label="设备名称" />
          <el-table-column prop="status" label="状态">
            <template #default="{ row }">
              <el-tag :type="row.status === '在线' ? 'success' : 'danger'">
                {{ row.status }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="power" label="功率" />
          <el-table-column prop="temperature" label="温度" />
        </el-table>
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import EnergyTrendChart from '@/components/charts/EnergyTrendChart.vue'
import EnergyDistributionChart from '@/components/charts/EnergyDistributionChart.vue'

const date = ref(new Date())
const timeRange = ref('day')

const deviceList = ref([
  {
    name: '空调主机',
    status: '在线',
    power: '3.2 kW',
    temperature: '24°C'
  },
  {
    name: '照明系统',
    status: '在线',
    power: '1.5 kW',
    temperature: '--'
  },
  {
    name: '实验设备A',
    status: '离线',
    power: '0 kW',
    temperature: '--'
  },
  {
    name: '通风系统',
    status: '在线',
    power: '2.8 kW',
    temperature: '--'
  }
])
</script>

<style scoped>
.dashboard {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h2 {
  margin: 0;
  font-size: 24px;
  color: #333;
}

.energy-overview {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  text-align: center;
}

.card-content h3 {
  margin: 10px 0;
  font-size: 24px;
  color: #333;
}

.card-content p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.charts-section {
  margin-bottom: 20px;
}

.chart-container {
  height: 300px;
}

.device-list {
  margin-bottom: 20px;
}
</style> 